﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Avatar.MembershipService;
using Avatar.Model;
using AvatarHelper;
using Avatar.Common;
using Avatar.OnlinePayment;

public partial class ChinaBank : System.Web.UI.Page
{
    #region 在线支付接口参数，暂时没用到的参数用以扩展开发
    //必要的交易信息
    public static string v_amount;      // 订单金额
    public static string v_moneytype;   // 币种
    public static string v_md5info;     // 对拼凑串MD5私钥加密后的值
    public static string v_mid;         // 商户号
    public static string v_key;         // 商户密钥
    public static string v_url;         // 返回页地址
    public static string v_goldurl;     // 支付提交页面
    public static string v_oid;         // 推荐订单号构成格式为 年月日-商户号-小时分钟秒

    //收货信息
    public static string v_rcvname;      // 收货人
    public static string v_rcvaddr;      // 收货地址
    public static string v_rcvtel;       // 收货人电话
    public static string v_rcvpost;      // 收货人邮编
    public static string v_rcvemail;     // 收货人邮件
    public static string v_rcvmobile;    // 收货人手机号

    //订货人信息
    public static string v_ordername;    // 订货人姓名
    public static string v_orderaddr;    // 订货人地址
    public static string v_ordertel;     // 订货人电话
    public static string v_orderpost;    // 订货人邮编
    public static string v_orderemail;   // 订货人邮件
    public static string v_ordermobile;  // 订货人手机号
    public static string pmode_id;
    //两个备注
    public static string remark1;
    public static string remark2;
    #endregion

    //sysAdmin CA = new sysAdmin();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GridView1.DataSource = PaymentManager.GetInterfaceList();
            GridView1.DataBind();

        }
    }

    //protected void ChinaBank_Button_Click(object sender, EventArgs e)
    //{
    //    if (Open.Checked)
    //        s_passed = "1";
    //    else
    //        s_passed = "0";
    //    v_mid = txt_BankSH.Text.Trim();
    //    v_key = txt_BankMS.Text.Trim();
    //    //SqlDataReader dr = (SqlDataReader)ExecuteReader(CommandType.Text, "select * from InterBank where BankName='网银在线'", null);
    //    var _bank = DBHelper.Get<InterBank>(b => b.BankName == "网银在线", "获取网银在线支付接口数据出错:");
    //    if (_bank==null) 
    //    {
    //        sql = "insert into interBank values ('网银在线','" + v_mid + "','" + v_key + "','" + s_passed + "')";
    //    } else 
    //    {
    //        sql = "update interBank set BankSH='" + v_mid + "',BankMS='" + v_key + "',Passed='" + s_passed + "' where BankName='网银在线'";
    //    }
    //    //MysqlExecute(sql);


    //}

    protected void btn_Submit_Click(object sender, EventArgs e)
    {
        if (PaymentManager.InterfaceEdit(
            txt_InterfaceName.Text,
            txt_BankSH.Text,
            txt_BankMS.Text,
            Open.Checked))
        {
            Helper.ShowMassage("接口设置成功", "ChinaBank.aspx");
        }
    }
    protected void btn_Update_Click(object sender, EventArgs e)
    {
        var _btn = sender as Button;
        int _id = string.IsNullOrEmpty(_btn.CommandArgument) ? 0 : Convert.ToInt32(_btn.CommandArgument);
        
        var _bank = PaymentManager.GetInterface(_id);
        if (_bank != null)
        {
            txt_InterfaceName.Text = _bank.BankName;
            txt_BankSH.Text = _bank.BankSH;
            txt_BankMS.Text = _bank.BankMS;
            Open.Checked = _bank.Passed;
        }
    }
}
